<template>
  <!-- 主体区域 -->
  <section id="app">
    <todo-header @add="hAdd"></todo-header>
    <todo-main @del="hDle" :list="list"></todo-main>
    <todo-footer :list="list" @clear="list=[]"></todo-footer>
  </section>
</template>

<script>
import TodoFooter from './components/TodoFooter.vue'
import TodoHeader from './components/TodoHeader.vue'
import TodoMain from './components/TodoMain.vue'
export default {
  components: { TodoHeader, TodoMain, TodoFooter },
  data () {
    return {
      list: JSON.parse(localStorage.getItem('list'))
      // list: [
      //   {id:1, name: '打篮球'},
      //   {id:2, name: '吃饭'},
      //   {id:3, name: '跑步'}
      // ]
    }
  },
  methods: {
    hAdd(name) {
      this.list.unshift({
        id: +new Date(),
        name
      })
    },
    hDle(id) {
      this.list = this.list.filter(item => item.id !== id)
    }
  },
  watch: {
    list: {
      deep: true,
      handler() {
        localStorage.setItem('list', JSON.stringify(this.list))
      }
    }
  }
}
</script>
                                                                                                                                
<style>

</style>
